//
//  SearchDetailViewController.m
//  video
//
//  Created by lanou3g on 15/5/29.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "SearchDetailViewController.h"
#import "URL.h"
@interface SearchDetailViewController ()

@end

@implementation SearchDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self read];
    [self layout];
   //NSLog(@"%@",self.strUrl);
    self.player.contentURL=[NSURL URLWithString:self.strUrl];
    [self.player play];
}
-(void)read{

    NSURL*url=[NSURL URLWithString:[NSString stringWithFormat:SearchDetailVideo,self.str]];
    NSURLRequest*request=[NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60.0];
    NSData*data=[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    
            if(data==nil){
            return ;
        }
        NSMutableDictionary*dic=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        NSMutableDictionary*dict1=[dic valueForKey:@"result"];
        NSMutableDictionary*dict2=[dict1 valueForKey:@"items"];
        NSMutableDictionary*dict3=[dict2 valueForKey:@"350"];
        NSMutableDictionary*dicVideo=[dict3 valueForKey:@"transcode"];
        self.strUrl=[dicVideo valueForKey:@"urls"][0];
        
   


}

-(void)layout{
    self.player=[[MPMoviePlayerController alloc]init];
    [self.view addSubview:self.player.view];
    NSLayoutConstraint *playerLeft=[NSLayoutConstraint constraintWithItem:self.player.view attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
    
    NSLayoutConstraint *playerTop=[NSLayoutConstraint constraintWithItem:self.player.view attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1.0 constant:0];
    
    NSLayoutConstraint *playerRight=[NSLayoutConstraint constraintWithItem:self.player.view attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeRight multiplier:1.0 constant:0];
     NSLayoutConstraint *playerBottom=[NSLayoutConstraint constraintWithItem:self.player.view attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
    [self.view addConstraints:@[playerLeft,playerRight,playerTop,playerBottom]];
   
    self.player.view.translatesAutoresizingMaskIntoConstraints=NO;
    
    
    
    
    
//    [UIView animateWithDuration:0.001 animations:^{
//        //通过修改transform设置视图旋转角度
//        
//           self.view.transform=CGAffineTransformRotate(self.view.transform, M_PI/2);
//            
//    }];
//    
//self.player.view.frame=CGRectMake(0, 0, CGRectGetHeight([UIScreen mainScreen].bounds), CGRectGetWidth([UIScreen mainScreen].bounds));
    

    UIBarButtonItem*LeftBI=[[UIBarButtonItem alloc]initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(back)];
    self.navigationItem.leftBarButtonItem=LeftBI;
    LeftBI.tintColor=[UIColor yellowColor];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)back{
    [self.navigationController popViewControllerAnimated:YES];

}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
